<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--bootstrap插件-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="/static/plugin/bootstrap/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="/static/plugin/jo/joUI.css" rel="stylesheet"/>
    <!--字体插件-->
    <link href="/static/plugin/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="/static/plugin/layui-2.4.3/css/layui.css" rel="stylesheet"/>
    <!--ztree-->
    <link href="/static/plugin/zTree/css/metroStyle/metroStyle.css" rel="stylesheet"/>
    <!--common-->
    <link href="/static/css/common.css" rel="stylesheet"/>
    <title>投票主信息表单</title>
</head>
<body>
<div class="container-fluid">
    <!--基本信息-->
    <!--<div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            &lt;!&ndash;按钮栏&ndash;&gt;
            <div class="form-group button-bar button-bar">
                <button type="button" isShow="joForm.isAdd" class="btn btn-primary" onclick="joForm.save()">
                    <i class="fa fa-plus-circle" aria-hidden="true"></i>&nbsp;新增
                </button>
                <button type="button" isShow="!joForm.isAdd" class="btn btn-info" onclick="joForm.update()">
                    <i class="fa fa-pencil-square" aria-hidden="true"></i>&nbsp;修改
                </button>
                <button type="button" isShow="!joForm.isAdd" class="btn btn-danger" onclick="joForm.del()">
                    <i class="fa fa-trash" aria-hidden="true"></i>&nbsp;删除
                </button>
            </div>
            &lt;!&ndash;按钮栏&ndash;&gt;
        </div>
    </div>-->
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <form id="pageForm" name="pageForm" action="" method="post">
                <!--<div class="young-form-item col-md-6">
                    <div class="young-form-label">投票信息编号</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block">
                        <input type="text"   name="id" value="" class="form-control " readonly />
                    </div>
                </div>-->
                <div class="young-form-item col-md-12" style="text-align: center;font-weight: 700;">
                    <!--<div class="young-form-label">标题</div>
                    <div class="young-form-tips"><span class="fa fa-info-circle" onmouseover="window.tipsIdx=jo.tips('例如:小组长投票选举',this,{tips:[2, '#3595CC'], time:10000});" onmouseout="jo.close(window.tipsIdx);"></span></div>
                    <div class="young-form-input-block" style="text-align: center;">
                        &lt;!&ndash;<input type="text"   name="title" value="" class="form-control "  ErrEmpty="标题不允许为空" />&ndash;&gt;

                    </div>-->
                    <span class="jo-form-txt" name="title"></span>
                </div>
                <div class="young-form-item col-md-12 " style="text-align: center;">
                    （<span class="jo-form-txt" name="startTime"></span>
                    ~
                    <span class="jo-form-txt" name="endTime"></span>）
                </div>
                <div class="young-form-item col-md-12 " style="text-indent: 2em;">
                    <!--<div class="young-form-label">内容</div>
                    <div class="young-form-tips"></div>
                    <div class="young-form-input-block">
                        &lt;!&ndash;<textarea  name="content" value="" class="form-control "   ></textarea>&ndash;&gt;
                    </div>-->
                    <span class="jo-form-txt" name="content"></span>
                </div>

            </form>
        </div>
    </div>

    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div class="table-responsive">
                <table class="table table-bordered table-hover table-line-auto" id="mainList" trHandle="trHandle" noHead="false">
                    <col field="check" title="选择" width="5%" align="" event="click" />
                    <col field="optionContent" title="选项内容" width="95%" align=""  />
                </table>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div class="form-group button-bar button-bar">
                <button type="button" isShow="!joForm.isAdd && joForm.formData && !joForm.formData.voteResult" class="btn btn-primary" onclick="goVote()">
                    <i class="fa fa-paper-plane-o" aria-hidden="true"></i>&nbsp;发起投票
                </button>
            </div>
        </div>
    </div>


</div>

<!--配置信息-->
<script src="/static/js/config.js"></script>
<!--jquery-->
<script src="/static/plugin/jquery/jquery-3.3.1.js"></script>
<script src="/static/plugin/jquery/jquery.cookie.js"></script>
<!--bootstrap-->
<script src="/static/plugin/bootstrap/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
<script src="/static/plugin/other/html5shiv.js"></script>
<script src="/static/plugin/other/respond.min.js"></script>
<![endif]-->
<!--layui-->
<script src="/static/plugin/layui-2.4.3/layui.all.js"></script>
<!--ztree-->
<script src="/static/plugin/zTree/js/jquery.ztree.all.js"></script>
<!--common-->
<script src="/static/js/common.js"></script>
<!--jo-->
<script src="/static/plugin/jo/jo.js"></script>
<script src="/static/plugin/jo/jo-adapt.js"></script>
<script src="/static/plugin/jo/jo-page-view.js"></script>
<script src="/static/plugin/jo/jo-page-form.js"></script>
<script src="/static/plugin/jo/jo-listener.js"></script>
<script type="text/javascript">
    layui.laydate.render({
        elem: '#startTime' //注册日期控件
    });
    layui.laydate.render({
        elem: '#endTime' //注册日期控件
    });
    /*layui.laydate.render({
        elem: '#createTime' //注册日期控件
    });
    layui.laydate.render({
        elem: '#updateTime' //注册日期控件
    });*/
    $(function(){
        var jParams = {
            "PKName" : "id",//主键属性名
            "saveAfter" : "toEdit",
            /*"addUrl" : "/bs/vote/voteInfo/insert",//新增
            "deleteUrl" : "/bs/vote/voteInfo/delete",//删除
            "updateUrl" : "/bs/vote/voteInfo/update",//修改*/
            "formDataUrl" : "/bs/vote/voteInfo/getDetail",//查询
            //"readonly2Label" : true //只读转文本
        };
        joForm.initFormPage(jParams);//初始化

    });
    //初始化新增页面回调函数(在初始化按钮前发生)
    joForm.initFormPageOfAdd = function(){

    };
    //初始化表单值前处理
    joForm.initFormValueBefore = function(oJson){
        oJson.startTime = jo.formatDate(oJson.startTime);
        oJson.endTime = jo.formatDate(oJson.endTime);
        oJson.createTime = jo.formatTime(oJson.createTime);
        oJson.updateTime = jo.formatTime(oJson.updateTime);
    };
    //初始化表单值后处理
    joForm.initFormValueAfter = function(oJson){
        //编辑页,根据投票主id查询选项信息列表
        if(!joForm.isAdd && joForm.params.PKValue){
            Grid('mainList').loadData("/bs/vote/voteOption/getList?voteId=" + joForm.params.PKValue);
        }
    };
    //新增请求提交前回调函数
    joForm.dealDataAtSaveBefore = function(oJson){

    };
    //修改请求提交前回调函数
    joForm.dealDataAtUpdateBefore = function(oJson){

    };
    /* 关于joForm更多回调函数和配置参数可查看jo-page-form.js */

    function trHandle(item){
        item.check = '<input type="radio" name="optionId" value="'+item.id+'">';
    }


    //表格渲染时行处理,参数1为当前行的数据对象,参数2为当前行的索引值(最小为0)
    joView.handleItem = function(oItem,iIndex){

    };
    //表格渲染完成后的回调,参数为表格数据(数组对象)
    joView.setGridDataAfter = function(oList){

    };

    function goVote(){
        var voteId = joForm.params.PKValue;//投票id
        if(!voteId){
            jo.showErrorMsg('投票ID无效');
            return;
        }
        var optionId = jo.getCheckBoxValue('optionId');//选项id
        if(!optionId){
            jo.showTipsMsg('请选择投票结果!');
            return;
        }
        var obj = {};
        for(var i=0;i<Grid('mainList').data.length;i++){
            var item = Grid('mainList').data[i];
            obj[item.id] = item.optionContent;
        }
        jo.confirm('您确定将票投给['+obj[optionId]+']吗?', function(idx){
            jo.postAjax('/bs/vote/voter/initiate', {voteId: voteId, optionId: optionId}, function(json){
                if(json && json.code == 0){
                    parent.jo.showSuccessMsg('操作成功');
                    parent.reloadCurrentPage();
                    jo.closeSelf();
                }else if(json && json.info){
                    jo.showErrorMsg(json.info);
                }else{
                    jo.showErrorMsg('操作失败');
                }
            });
            jo.close(idx);
        });

    }
</script>
</body>
</html>
